async function getUsers() {
  const resp = await fetch("https://study.duyiedu.com/api/herolist");
  console.log(resp);
  const _type = resp.headers.get("Content-Type");
  console.log(_type);
}
getUsers();



const doms = {
  avatar: document.querySelector("#avatar"),
  preview: document.querySelector("#preview"),
};

doms.avatar.addEventListener("change", async (e) => {
  const _file = e.target.files[0];
  console.log(_file);
  const render = new FileReader();
  render.onload = (e) => {
    console.log(e.target.result);
    preview.src = e.target.result;
    preview.style.display = "block";
  };
  render.readAsDataURL(_file);
  upload(_file);
});

function upload(file) {
  const xhr = new XMLHttpRequest();
  const url = "";
  xhr.open("post", url);
  xhr.onload = (e) => {
    console.log(e.target.response);
  };
  xhr.upload.onprogress = (e) => {
    console.log(e.loaded / e.total);
  };
  const formData = new FormData();
  formData.append("avatar", file);
  xhr.send(formData);
}
